package  networkSimulation.framework

/**
 * Directed Graph class
 *
 * @author  Tim Caljé
 *          Jeroen De Raedt
 *          Jorick Van Aken
 */
case class DirectedGraph[N <% Node, E <% Edge[N]]() extends Graph[N,E] {

  /**
   * Method which retrieves the neighbours of a given node
   * @param   n : N
   *          The node of which we want to retrieve the neighbours
   * @return  List[N]
   *          A list of neighbour nodes
   */
  @Override
   override def getNeighbours(n : N) : List[N] = {
    var neighbours = List[N]()
    for (e <- this.edges) {
      if (e.from.equals(n)) {
        neighbours ::= e.to
      }      
    }
    neighbours
  }

  /**
   * Method which retrieves the edges linking to a given node
   * @param   n : N
   *          The node of which we want to retrieve the linking nodes
   * @return  List[N]
   *          A list of linking edges to the given node
   */
  @Override
  override def getEdgesTo(n: N) : List[E] = {
    var links = List[E]()
    for(e: E <- this.edges) {
      if(e.to == n) {
        links = links :+ e
      }
    }
    links
  }

   /**
   * Get the type of this graph as a String
   */
  @Override
  override def getGraphType() : String = "UndirectedGraph"
}